import {Toast} from 'vant'
import UserAPI from '../../../repo/api/UserAPI'
import IdentityCover from '../../plan/components/IdentityCover'
import uploaderHandPic from '@/components/uploaderHandPic'
import VantOverLayBindMobile from '@/components/VantOverLayBindMobile'
import myInfoItem from '@/components/myInfoItem'
import VantOverLayCommon from '@/components/VantOverLayCommon'
import pickerGender from '@/components/pickerGender'

let MyInfoMixIn = {
  data () {
    return {
      name: '我的信息',
      myInfo: [],
      edu: ['高中以下', '高中', '大专', '大学本科', '双学士学位或研究生', '硕士', '博士'],
      storeUserInfo: {},
      show: false,
      showCommon: false,
      pickerShow: false,
      currentCity: '',
      tempCity: {},
    }
  },
  components: {
    IdentityCover,
    uploaderHandPic,
    VantOverLayBindMobile,
    myInfoItem,
    VantOverLayCommon,
    pickerGender
  },
  watch: {
    show (n, o) {
      if (o != n) {
        this.fetchData()
      }
    },
  },
  created () {
    this.fetchData()
  },
  methods: {
    fetchData() {
      Toast.loading({
        duration: 0,
        message: '正在加载',
        forbidClick: true,
        loadingType: 'spinner',
      })


      UserAPI.verifyIDCard().then((result) => {
        let data = null
        this.storeUserInfo = this.$store.getters.userInfo
        let scopeStore = JSON.stringify(this.storeUserInfo)
        this.storeUserInfo = JSON.parse(scopeStore)

        if (result.responseData) {
          data = result.responseData
          this.storeUserInfo.cardName = data.cardName
          this.storeUserInfo.idcard = data.idcard
        } else {
          this.storeUserInfo.cardName = ''
          this.storeUserInfo.idcard = ''
        }

        if (this.storeUserInfo.cityname === '未知城市') {
          this.storeUserInfo.cityname = ''
        }
        Toast.clear()
      })
    },

    cancelFun () {
      this.showCommon = false
      this.show = false
    },
  },
}
export default MyInfoMixIn
